package ch05;

import ch05.aop.UsersDao;
import ch05.ioc.Hello;
import ch05.ioc.Person;
import ch05.ioc.Printer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {
    private static ApplicationContext applicationContext  ;
    private static  ApplicationContext aopContext ;
    static {
        applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml" ) ;
        aopContext = new ClassPathXmlApplicationContext("aop.xml") ;

    }
    private  static  void testSay(){
        //1.读取spring的配置文件
       // ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml") ;
        Hello hello = (Hello) applicationContext.getBean("hello") ;
        hello.say();
    }

    public  static  void testPerson(){
        //1.

        Person person = (Person) applicationContext.getBean("person") ;
        person.say();
    }

    public static void testPrinter(){
        //1
        Printer printer = (Printer) applicationContext.getBean("printer") ;
        printer.print();
    }

    public static  void testLoggerBefore(){
        UsersDao usersDao = (UsersDao) aopContext.getBean("usersDao") ;
        usersDao.save();
    }


    public static void main(String[] args) {
        //testSay();
        //testPerson() ;
        //testPrinter() ;
        testLoggerBefore() ;
    }


}
